<template>
  <div class="app-container">
    <el-form :inline="true" :model="filters" ref="refForm" class="demo-form-inline filter-container">
      <el-form-item prop="date" label="查询时间">
        <el-date-picker
          v-model="filters.date"
          class="filter-item"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
          value-format="yyyy-MM-dd HH:mm:ss"
          unlink-panels
          align="right">
        </el-date-picker>
      </el-form-item>
      <el-form-item prop="accountType">
        <el-select v-model="filters.accountType">
          <el-option v-for="item in consts.ACCOUNT_TYPE"
                     :key="item.value"
                     :label="item.title"
                     :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="username">
        <el-input v-model="filters.username" placeholder="输入账户名"/>
      </el-form-item>


      <el-button type="primary" v-waves icon="el-icon-search" @click="gridSearch">搜索</el-button>
      <el-button @click="resetFilter">重置</el-button>
    </el-form>

    <el-table :data="tableData.list" v-loading="loading" element-loading-text="给我一点时间" border fit
              highlight-current-row
              style="width: 100%">
      <el-table-column label="活动名称" align="center" prop="activeName">
      </el-table-column>
      <el-table-column label="参与人数" align="center" prop="num">
      </el-table-column>
      <el-table-column label="参与次数" align="center" prop="times">
      </el-table-column>
      <el-table-column label="红利总金额" align="center" prop="amount">
      </el-table-column>
    </el-table>

    <!--<div class="pagination-container">-->
    <!--<el-pagination background @size-change="gridSizeChange" @current-change="gridCurrentChange"-->
    <!--:current-page="filters.page" :page-sizes="gridPageSize" :page-size="filters.size"-->
    <!--:layout="gridLayout" :total="tableData.total">-->
    <!--</el-pagination>-->
    <!--</div>-->


  </div>
</template>

<script>
  import {form, grid, dialog} from '@/build';

  import {
    marketingOfferExpenditureListApi as listApi,
  } from '@/services/api/marketing';

  import OfferEdit from './offerEdit';

  export default {
    name: 'offer-expenditure-list',

    mixins: [form, grid, dialog],

    components: {
      OfferEdit,
    },

    data() {
      return {
        operatorList: [],
        tableData: [],
        filters: {
          page: 1,
          size: 20,
          fromTime: undefined,
          endTime: undefined,
          accountType: -1,
          username: undefined,
          clientType: undefined,
          date: [moment(consts.ONLINE_DATE).format('YYYY-MM-DD 00:00:00'), moment().format('YYYY-MM-DD 23:59:59')]
        },
        filterDateType: false,
      }
    },

    methods: {
      resetFilter() {
        this.resetForm('refForm')
        this.gridSearch();
      }
    },

    mounted() {
      let {username, time} = this.$route.query
      if (username) this.filters.username = username
      if (time) this.filters.date = [moment(time[0]).format('YYYY-MM-DD 00:00:00'), moment(time[1]).format('YYYY-MM-DD 23:59:59')]
      this.bindGet(listApi, 'tableData', {
        action: 'getGrid',
        sendingData: 'filters',
      }), {
        beforeSend: data => {
          const {time} = data;
          let regFromTime, regEndTime;
          if (!_.isUndefined(time) && _.isArray(time)) {
            fromTime = time[0]
            endTime = time[1];
          }
          return {...data, regFromTime, regEndTime}
        },
      };

      this.getAll();
    }
  }
</script>
